package com.fz.controller;

import com.fz.entity.Region;
import com.fz.service.RegionService;
import com.fz.vo.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 存储区域名称与位置信息 前端控制器
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
@RestController
@RequestMapping("/region")
public class RegionController {
    @Resource
    RegionService regionService;
    @GetMapping("/list")
    ResultVo<List<Region>> list() {
        return ResultVo.success(regionService.list());
    }
    @PostMapping("/add")
    ResultVo<Boolean> add(String name,String address) {
        return ResultVo.success(regionService.add(name,address),"添加区域成功");
    }
    @GetMapping("/getById")
    ResultVo<Region> getById(long id){
        return ResultVo.success(regionService.getById(id));
    }
    @PostMapping("/update")
    ResultVo<Boolean> update(Long id,String name,String address){
        return  ResultVo.success(regionService.update(id,name,address),"修改区域成功");
    }
    @PostMapping("/del")
    ResultVo<Boolean> del(Long id){
        return  ResultVo.success(regionService.del(id),"删除区域成功");
    }
    @PostMapping("/dele")
    ResultVo<Boolean> dele(Long id,Boolean status){
        return ResultVo.success(regionService.dele(id,status),status ? "启用区域成功" : "禁用区域成功");
    }
}
